﻿using System;
using System.Collections.Generic;
using System.Text;
using BarCode.Bean;
using BarCode.Common;
using System.Data;
using BarCode.Module;
using MySql.Data.MySqlClient;
using System.Windows.Forms;

namespace BarCode.AccessDao
{
    public class DB01Dao
    {
        private static readonly log4net.ILog LogUtil = log4net.LogManager.GetLogger(typeof(DB01Dao));

        private MySqlHelper db01;
        public DB01Dao()
        {
            db01 = new MySqlHelper(GlobalVal.MysqlServerInfo.SERVER_IP, "db_01", GlobalVal.MysqlServerInfo.USERID, GlobalVal.MysqlServerInfo.USERPWD);
        }

        /// <summary>
        /// 判断是否可链接
        /// </summary>
        /// <returns></returns>
        public bool EnableConnect()
        {
            return db01.EnableConnect();
        }


        /// <summary>
        /// 获取订单对应的表号范围一览
        /// </summary>
        /// <returns></returns>
        public DataTable selectOrderBHList(string orderId)
        {
            String selectSql = "select t.listID,t.orderID,t.meters_code,t.meters_directions,t.meters_IDstart,t.meters_IDend,t.meters_tolmax,t.meters_tolmin,t.meter_precision,t.customer_code customer_name from tblmnoprn_pre t where t.orderID = @orderId and t.istest='未测'";
            DataSet retSet = db01.GetDataSet(CommandType.Text, selectSql, new MySqlParameter("@orderId", orderId));
            if (retSet != null && retSet.Tables.Count > 0)
            {
                return retSet.Tables[0];
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        ///  测试完成
        /// </summary>
        public int completeTest(int listID)
        {
            try
            {
                string updSql = "update tblmnoprn_pre set istest='已测' where listID = @listID";
                MySqlParameter[] updParams = new MySqlParameter[1];
                updParams[0] = new MySqlParameter("@listID", listID);
                int updCnt = db01.ExecuteNonQuery(CommandType.Text, updSql, updParams);
                if (updCnt == 0)
                {
                    return Consts.RET_FAIL;
                }
            }
            catch (Exception e)
            {
                LogUtil.Error(e);
                return Consts.RET_FAIL;
            }
            return Consts.RET_SUCCESS;
        }
    }
}

